package com.xhh.nphm.system.mapper;

import com.xhh.nphm.system.domain.TtelBlackEty;
import com.xhh.nphm.system.domain.TtelRedEty;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TelNameListDao {
    @Select("select PkId,TelNo,TelName,convert(varchar(19),BkTime,20) BkTime,BkName,Remark from tTelBlack where  IsDel=0 [[and PkId=#{pkId}]] [[and TelNo like #{telNo}]] [[and TelName like #{telName}]]  order by TimeEdit desc")
    List<TtelBlackEty> listBlack(TtelBlackEty ttelBlackEty);

    @Select("select PkId,TelNo,TelName,convert(varchar(19),RedTime,20) RedTime,RedName,Remark from tTelRed where  IsDel=0 [[and PkId=#{pkId}]] [[and TelNo like #{telNo}]] [[and TelName like #{telName}]] order by TimeEdit desc")
    List<TtelRedEty> listRed(TtelRedEty ttelRedEty);

    @Insert("INSERT INTO tTelBlack ( telNo, telName, telAddress, bkTime, bkCode, bkName, timeEdit, remark, spareInt, spareString, flagInt, flagString ) VALUES (#{telNo}, #{telName}, #{telAddress}, #{bkTime}, #{bkCode}, #{bkName}, #{timeEdit}, #{remark}, #{spareInt}, #{spareString}, #{flagInt}, #{flagString})")
    int insertBlack(TtelBlackEty ttelBlackEty);

    @Insert("INSERT INTO tTelRed ( telNo, telName, telAddress, redTime, redCode, redName, timeEdit, remark, spareInt, spareString, flagInt, flagString ) VALUES (#{telNo}, #{telName}, #{telAddress}, #{redTime}, #{redCode}, #{redName}, #{timeEdit}, #{remark}, #{spareInt}, #{spareString}, #{flagInt}, #{flagString})")
    int insertRed(TtelRedEty ttelRedEty);

    @Update("<script>" +
            "UPDATE tTelBlack SET IsDel=1  WHERE PkId IN" +
            " <foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach>"
            +"</script>")
    int deleteBlackBatchIds(Integer... ids);

    @Update("<script>" +
            "UPDATE tTelRed SET IsDel=1  WHERE PkId IN" +
            " <foreach collection='array' item='id' open='(' separator=',' close=')'>#{id}</foreach>"
    +"</script>")
    int deleteRedBatchIds(Integer... ids);

    @Update("UPDATE tTelRed SET telNo=#{telNo}, telName=#{telName}, telAddress=#{telAddress}, redTime=#{redTime}, redCode=#{redCode}, redName=#{redName}, timeEdit=#{timeEdit}, remark=#{remark}, spareInt=#{spareInt}, spareString=#{spareString}, flagInt=#{flagInt}, flagString=#{flagString} WHERE PkId=#{pkId}")
    int editRed(TtelRedEty ttelRedEty);

    @Update("UPDATE tTelBlack SET telNo=#{telNo}, telName=#{telName}, telAddress=#{telAddress}, bkTime=#{bkTime}, bkCode=#{bkCode}, bkName=#{bkName}, timeEdit=#{timeEdit}, remark=#{remark}, spareInt=#{spareInt}, spareString=#{spareString}, flagInt=#{flagInt}, flagString=#{flagString} WHERE PkId=#{pkId}")
    int editBlack(TtelBlackEty ttelBlackEty);
}
